<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>混合起来 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/slop.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/slop.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/slop.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/slop.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="search-in-depth.html">深入搜索</a></span>
»
<span class="breadcrumb-link"><a href="proximity-matching.html">近似匹配</a></span>
»
<span class="breadcrumb-node">混合起来</span>
</div>
<div class="navheader">
<span class="prev">
<a href="phrase-matching.html">« 短语匹配</a>
</span>
<span class="next">
<a href="_multivalue_fields_2.html">多值字段 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="slop"></a>混合起来<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/120_Proximity_Matching/10_Slop.asciidoc">edit</a>
</h2>
</div></div></div>
<p>精确短语匹配  或许是过于严格了。也许我们想要包含 “quick brown fox” 的文档也能够匹配 “quick fox,” ， 尽管情形不完全相同。</p>
<p>我们能够通过使用 <code class="literal">slop</code> 参数将灵活度引入短语匹配中：</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET /my_index/my_type/_search
{
    "query": {
        "match_phrase": {
            "title": {
            	"query": "quick fox",
            	"slop":  1
            }
        }
    }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/120_Proximity_Matching/10_Slop.json"></div>
<p><code class="literal">slop</code> 参数告诉 <code class="literal">match_phrase</code> 查询词条相隔多远时仍然能将文档视为匹配  。 相隔多远的意思是为了让查询和文档匹配你需要移动词条多少次？</p>
<p>我们以一个简单的例子开始吧。 为了让查询 <code class="literal">quick fox</code> 能匹配一个包含 <code class="literal">quick brown fox</code> 的文档， 我们需要 <code class="literal">slop</code> 的值为 <code class="literal">1</code>:</p>
<pre class="literallayout">            Pos 1         Pos 2         Pos 3
-----------------------------------------------
Doc:        quick         brown         fox
-----------------------------------------------
Query:      quick         fox
Slop 1:     quick                 ↳     fox</pre>

<p>尽管在使用了 <code class="literal">slop</code> 短语匹配中所有的单词都需要出现， 但是这些单词也不必为了匹配而按相同的序列排列。 有了足够大的 <code class="literal">slop</code> 值， 单词就能按照任意顺序排列了。</p>
<p>为了使查询 <code class="literal">fox quick</code> 匹配我们的文档， 我们需要 <code class="literal">slop</code> 的值为 <code class="literal">3</code>:</p>
<pre class="literallayout">            Pos 1         Pos 2         Pos 3
-----------------------------------------------
Doc:        quick         brown         fox
-----------------------------------------------
Query:      fox           quick
Slop 1:     fox|quick  ↵  <a id="CO82-1"></a><i class="conum" data-value="1"></i>
Slop 2:     quick      ↳  fox
Slop 3:     quick                 ↳     fox</pre>

<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO82-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>注意 <code class="literal">fox</code> 和 <code class="literal">quick</code> 在这步中占据同样的位置。 因此将 <code class="literal">fox quick</code> 转换顺序成 <code class="literal">quick fox</code> 需要两步， 或者值为 <code class="literal">2</code> 的 <code class="literal">slop</code> 。</p>
</td>
</tr>
</table>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="phrase-matching.html">« 短语匹配</a>
</span>
<span class="next">
<a href="_multivalue_fields_2.html">多值字段 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>